package com.intel.factorytest.activity;


import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.intel.factorytest.R;
import com.intel.factorytest.TestFileOp;

public class DeleteServiceResultActivity extends Activity {

    List testMenuItems = null;
    StringBuilder mFailedItems = new StringBuilder();
    private TextView mTextView;
    private String  tName;
    private File  sampleDir;
    private File  sampleDir1;
    private boolean  isFirst = true;
    private static final String  TAG = "DeleteServiceResultActivity";
    Map<String, Object> testItem = new HashMap<String,Object>();
    private String Sm_nvm_result ="/data/Linux/Marvell/NVM/result.txt";
    private String Se_nvm_result ="/data/Linux/Marvell/NVM/result_s.txt";
    private String data_sm_result = "/data/data/com.intel.factorytest/result.txt";  
    private String data_se_result = "/data/data/com.intel.factorytest/result_s.txt";
    private TestFileOp mTestFile = new TestFileOp();
    private int isSys = 0;
    File smfile;
    File sefile;
    File datasmfile;
    File datasefile;    

@Override
    public void onCreate(Bundle savedInstanceState)
    {        
        smfile = new File(Sm_nvm_result);
        sefile = new File(Se_nvm_result);
        datasmfile = new File(data_sm_result);
        datasefile = new File(data_se_result);
        showDialog(0);
        super.onCreate(savedInstanceState);
    }
@Override
    protected Dialog onCreateDialog(int none){

        AlertDialog.Builder builder = new AlertDialog.Builder(DeleteServiceResultActivity.this)
//            .setIcon(R.drawable.alert_dialog_icon)
            .setTitle(R.string.SERVICEMENU_SHOW_RESULT)
            .setMessage("")
            .setPositiveButton(R.string.SERVICEMENU_OK_TXT, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                    /*
                        if (smfile != null) {
                            smfile.delete();
                            smfile = new File(Sm_nvm_result);
                        }
                        if (sefile != null) {
                            sefile.delete();
                            sefile = new File(Se_nvm_result);
                        }
                        if (datasmfile != null) {
                            datasmfile.delete();
                            datasmfile = new File(data_sm_result);
                        }
                        if (datasefile != null) {
                            datasefile.delete();
                            datasefile = new File(data_se_result);
                        }
                    */
                        
                        BufferedReader reader=null;
                        BufferedReader reader1=null;
                        try {
                            if (datasmfile != null) {
                                datasmfile.delete();
                                datasmfile.createNewFile();
                            }
                            if (datasefile != null) {
                                datasefile.delete();
                                datasefile.createNewFile();
                            }
                        } catch (IOException e) {
                            Log.e(TAG,"read  result failed");
                        }finally{
                        }
                        finish();    
                //        return;
                    }
                    })
        .setNegativeButton(R.string.SERVICEMENU_CANCEL_TXT, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    finish();
            //    return;
                }
                });
        AlertDialog dialog = builder.create();
        dialog.setCancelable(false);
        return dialog;
    }
@Override
    protected void onPrepareDialog(int id, Dialog dialog) {
        String msg = "delete the result file?";
        ((AlertDialog)dialog).setMessage(msg);
    }
}
